package com.example.springboot.ehcache.web;

import com.example.springboot.ehcache.entity.User;
import com.example.springboot.ehcache.service.UserService;
import com.example.springboot.ehcache.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @desc 操作数据库查询示例
 * @Author wangsh
 * @date 2018/5/6 15:01
 * @return
 */
@RestController
@RequestMapping("/user")
public class UserController {

    /**
     * 通过mybatis xml配置文件读取数据
     */
    @Autowired
    private UserService userService;

    @RequestMapping("/getUserById")
    @ResponseBody
    public User getUserById(String id) {
        User User = userService.getUserById(id);
        return User;
    }

    @RequestMapping("/save")
    @ResponseBody
    public User save() {
        User user = new User();
        user.setId(UUIDUtil.getUUID());
        user.setUsername("lisi");
        user.setPassword("lisi");
        userService.save(user);
        return user;
    }

    @RequestMapping("/queryList")
    @ResponseBody
    public List<User> queryList() {
        List<User> queryList = userService.queryList();
        return queryList;
    }
}
